<?php
namespace Home\Controller;
use Think\Controller;
class loginController extends Controller
{

    public function login(){

        if(IS_AJAX){  //判断是否是AJAX请求
            $username = I('post.username');
            $password = encrypt_password(trim(I('post.password')));

            $res= M('user')->where(array('username' => $username, 'password' => $password))->find();
           // echo M('user')->getlastsql();die;

            if($res){
                session('username',$username);
                session('password',$password);
               $message=array(
                   'error'=> 0,
                    'message'=> '登录成功',
                );
            }else{
                $message=array(
                    'error'=>1,
                    'message'=>'登录失败',
                );
            }
            $this->ajaxReturn($message);

        }
        $this->display();
    }

    public function register(){
        $this->display();
    }


}